import Vue from "vue";
import VueRouter from "vue-router";
import Login from "@/views/Login";
import Layout from "@/views/Layout";
import Home from "@/views/Home";

const self = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return self.call(this, location).catch(err => err);
};
Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "Login",
    component: Login
  },
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "/",
        name: "Home",
        component: Home,
        meta: { isKeep: true }
      },
      {
        path: "/question",
        name: "Question",
        component: () => import("@/views/Question") //懒加载，除了需要首页，一打开就要展示给用户看的组件之外，其余的可以懒加载
      },
      {
        path: "/user",
        name: "User",
        component: () => import("@/views/User")
      },
      {
        path: "/video",
        name: "Video",
        component: () => import("@/views/Video")
      }
    ]
  },
  {
    path: "/user/profile",
    component: () => import("@/views/User/profile.vue")
  },
  {
    path: "/user/chat",
    component: () => import("@/views/User/chat.vue")
  },
  {
    path: "/search",
    name: "Search",
    component: () => import("@/views/Search/index.vue")
  },
  {
    path: "/search/result",
    name: "SearchResult",
    component: () => import("@/views/Search/result.vue")
  },
  {
    // 这个路由是打算以动态路由的方式来传入文章编号
    path: "/article/:id",
    name: "Article",
    component: () => import("@/views/Article")
  }
  // {
  //   path: "/about",
  //   name: "About",
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () =>
  //     import(/* webpackChunkName: "about" */ "../views/About.vue")
  // }
];

const router = new VueRouter({
  routes
});

export default router;
